package com.hmy.monitor.web.controller;

import com.hmy.common.exception.Result;
import com.hmy.monitor.prometheus.web.CustomUrlMonitor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/test")
public class PrometheusTestController {

    @Autowired
    private CustomUrlMonitor customUrlMonitor;

    @GetMapping("/getData")
    Result getData() {
        customUrlMonitor.getRequestCount().increment();
        long startTime = System.currentTimeMillis();
        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        long endTime = System.currentTimeMillis();
        customUrlMonitor.getRequestTimer().record(endTime - startTime, TimeUnit.MICROSECONDS);
        return Result.succeed("return data");
    }

}
